package com.qyhl.module_home.city;

import com.qyhl.module_home.common.HomeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.home.CityBean;

/**
 * Created by qyhl on 2017/11/24.
 */

public class CityModel implements CityContract.CityModel {
    private CityPresenter mPresenter;

    public CityModel(CityPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取城市数据
     */
    @Override
    public void getData() {

        EasyHttp.get(HomeUrl.GET_CITY)
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("siteId", String.valueOf(CommonUtils.getInstance().getSite()))
                .execute(new SimpleCallBack<CityBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202 || e == null) {
                            mPresenter.setError(1, "暂无任何数据！");
                        } else {
                            mPresenter.setError(2, "数据加载出错，请重新尝试！");
                        }
                    }

                    @Override
                    public void onSuccess(CityBean cityBean) {
                        mPresenter.setData(cityBean);
                    }
                });
    }
}
